package com.wc.算法提高课.A第一章_动态规划.树形DP.皇宫看守;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/13 11:52
 * @description https://www.acwing.com/problem/content/1079/
 */

public class Main {
    /**
     * 思路：树形DP
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1510, idx = 1, INF = 0x3f3f3f3f;
    static int[] h = new int[N], e = new int[N], ne = new int[N], w = new int[N];
    // f[i][j] 表示点i的状态为当前点状态为j
    // j = 0 表示被父节点看着,自己没有守卫
    // j = 1 表示被子节点看着,自己没有守卫
    // j = 2 表示自己有守卫
    static int[][] f = new int[N][3];
    static boolean[] st = new boolean[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            int a = sc.nextInt(), cost = sc.nextInt(), m = sc.nextInt();
            w[a] = cost;
            for (int j = 1; j <= m; j++) {
                int b = sc.nextInt();
                st[b] = true;
                add(a, b);
            }
        }
        int root = 1;
        while (st[root]) root++;
        dfs(root);
        // 为什么没有f[root][0] 因为他没有父节点
        out.println(Math.min(f[root][1], f[root][2]));
        out.flush();
    }

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    static void dfs(int u) {
        f[u][2] = w[u];
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            dfs(j);
            f[u][0] += Math.min(f[j][1], f[j][2]);
            f[u][2] += Math.min(Math.min(f[j][0], f[j][1]), f[j][2]);
        }
        // 计算被哪一个子节点看着,如果没有子节点看着，说明这里就是INF
        f[u][1] = INF;
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            f[u][1] = Math.min(f[u][1], f[j][2] + f[u][0] - Math.min(f[j][1], f[j][2]));
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
